package action.article;

import java.util.Map;

import org.apache.struts2.ServletActionContext;

import service.ArticleService;
import service.UserService;
import bean.User;

import com.opensymphony.xwork2.ActionSupport;

public class CheckArticlesAction extends ActionSupport {
	private int classid;
	private UserService userService;
	private ArticleService articleService;
	@Override
	public String execute() throws Exception {
		Map session=ServletActionContext.getContext().getSession();
		User u=(User) session.get("user");
		User user=userService.login(u);
		ServletActionContext.getRequest().setAttribute("user", user);
		if(classid==0){
			ServletActionContext.getRequest().setAttribute("articles", user.getArticles());
		}else{
			ServletActionContext.getRequest().setAttribute("articles",articleService.getArticlesByClassid(classid) );
		}
		return SUCCESS;
	}
	public UserService getUserService() {
		return userService;
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	public int getClassid() {
		return classid;
	}
	public void setClassid(int classid) {
		this.classid = classid;
	}
	public ArticleService getArticleService() {
		return articleService;
	}
	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}
	
}
